<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <style>
        .remote_field{
            display: none;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">策略名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" value="{$info.name}" placeholder="请输入上传策略的名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">允许后缀</label>
                <div class="layui-input-block">
                    <input type="text" name="filetype" value="{$info.filetype}" placeholder="请输入文件后缀" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">多个请以半角逗号","隔开，留空表示不限制。如"png,jpg"</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">存储服务器</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required" lay-filter="server_select" disabled>
                        <option value="local" {eq name="$info.type" value="local"}selected{/eq}>本地</option>
                        <option value="remote" {eq name="$info.type" value="remote"}selected{/eq}>远程</option>
                        <option value="aliyunoss" {eq name="$info.type" value="aliyunoss"}selected{/eq}>阿里云OSS</option>
                        <option value="txyunoss" {eq name="$info.type" value="txyunoss"}selected{/eq}>腾讯云C0S</option>
                    </select>
                    <div class="layui-form-mid layui-word-aux">文件存储的服务器</div>
                </div>
            </div>

            <div class="other-field">

            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                保存修改
            </button>
        </div>
    </div>
</form>

{eq name="$info.type" value="local"}
<script id="field_local" type="text/html">
    <div class="layui-form-item">
        <label class="layui-form-label">存储目录</label>
        <div class="layui-input-block">
            <input type="text" name="save_dir" value="{$info.config.save_dir}" placeholder="请输入文件存放的目录"  lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">请以根目录 / 开始，结尾要加"/"，例如：/uploads/</div>
        </div>
    </div>
</script>
{/eq}

{eq name="$info.type" value="remote"}
<script id="field_remote" type="text/html">
    <div class="layui-form-item">
        <label class="layui-form-label">存储目录</label>
        <div class="layui-input-block">
            <input type="text" name="save_dir" value="{$info.config.save_dir}" placeholder="请输入文件存放的目录" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">请以根目录 / 开始，结尾要加"/"，例如：/uploads/</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">远程Token</label>
        <div class="layui-input-block">
            <input type="text" name="access_token" value="{$info.config.access_token}" placeholder="AccessToken" lay-verify="required" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请与远程服务端配置文件中保持一致</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">服务端URL</label>
        <div class="layui-input-block">
            <input type="text" name="server_uri" value="{$info.config.server_uri}" placeholder="服务端URL" lay-verify="required" class="layui-input">
            <div class="layui-form-mid layui-word-aux">请填写合法的URL地址，结尾要加"/"</div>
        </div>
    </div>

</script>
{/eq}

{eq name="$info.type" value="aliyunoss"}
<script id="field_aliyunoss" type="text/html">
    <div class="layui-form-item">
        <label class="layui-form-label">存储目录</label>
        <div class="layui-input-block">
            <input type="text" name="save_dir" value="{$info.config.save_dir}" placeholder="请输入文件存放的目录" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">请以根目录 / 开始，结尾要加"/"，例如：/uploads/</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Endpoint</label>
        <div class="layui-input-block">
            <input type="text" name="endpoint" value="{$info.config.endpoint}" placeholder="Endpoint" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">OSS Endpoint</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Bucket</label>
        <div class="layui-input-block">
            <input type="text" name="bucket" value="{$info.config.bucket}" placeholder="Bucket" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">OSS Bucket</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">AccessKey</label>
        <div class="layui-input-block">
            <input type="text" name="access_key" value="{$info.config.access_key}" placeholder="AccessKey" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">OSS AccessKey</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">AccessKeySecret</label>
        <div class="layui-input-block">
            <input type="text" name="access_secret" value="{$info.config.access_secret}" placeholder="AccessKeySecret" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">OSS AccessKeySecret</div>
        </div>
    </div>

</script>
{/eq}

{eq name="$info.type" value="txyunoss"}
<script id="field_txyunoss" type="text/html">
    <div class="layui-form-item">
        <label class="layui-form-label">存储目录</label>
        <div class="layui-input-block">
            <input type="text" name="save_dir" value="{$info.config.save_dir}" placeholder="请输入文件存放的目录" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">请以根目录 / 开始，结尾要加"/"，例如：/uploads/</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">SecretId</label>
        <div class="layui-input-block">
            <input type="text" name="secret_id" value="{$info.config.secret_id}" placeholder="SecretId" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">COS SecretId</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">SecretKey</label>
        <div class="layui-input-block">
            <input type="text" name="secret_key" value="{$info.config.secret_key}" placeholder="SecretKey" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">COS SecretKey</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Bucket</label>
        <div class="layui-input-block">
            <input type="text" name="bucket" value="{$info.config.bucket}" placeholder="Bucket" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">COS Bucket</div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">Region</label>
        <div class="layui-input-block">
            <input type="text" name="region" value="{$info.config.region}" placeholder="Region" lay-verify="required" autocomplete="off"  class="layui-input">
            <div class="layui-form-mid layui-word-aux">COS Region 存储桶地域</div>
        </div>
    </div>
</script>
{/eq}

<script src="/static/component/layui/layui.js"></script>
<script src="/static/component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        function setFieldHtml(field){
            let field_name = '#field_' + field;
            let html = $(field_name).html();

            if(typeof html !== "undefined"){
                $(".other-field").html(html);
                return true;
            }

            $(".other-field").html("");
            return false;
        }

        setFieldHtml('{$info.type}');

        form.on('submit(save)', function(data){
            $.ajax({
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                type:'post',
                success:function(res){
                    //判断有没有权限
                    if(res && res.code == 999){
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    }else if(res.code == 200){
                        layer.msg(res.msg,{icon:1,time:1000},function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>